package com.example.order.controller;

import com.example.common.util.core.resultbody.AjaxResult;
import com.example.common.util.enums.OrderStatusEnums;
import com.example.model.domain.entity.order.OrderInfo;
import com.example.model.vo.order.OrderCountQueryVo;
import com.example.model.vo.order.OrderQueryVo;
import com.example.order.service.OrderInfoService;
import com.example.service.util.conversion.OrderInfoConversion;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Author juzipi
 * @Date 2021/7/28 9:39
 * @Info
 */
@Api(tags = "后台订单管理")
@RestController
@RequestMapping("admin/order/order")
public class OrderInfoController {


    @Autowired
    private OrderInfoService orderInfoService;


    //获取分页列表
    @ApiOperation("获取订单分页列表")
    @GetMapping("page/{pageNum}/{pageSize}")
    public AjaxResult getOrderInfoPage(@PathVariable("pageNum") Integer pageNum,
                            @PathVariable("pageSize") Integer pageSize,
                            OrderQueryVo orderQueryVo){
        PageInfo<OrderInfo> orderInfoPage = orderInfoService.getOrderInfoPage(pageNum, pageSize, orderQueryVo);
        return AjaxResult.success(orderInfoPage);
    }


    //获取订单状态
    @ApiOperation("获取订单状态集合")
    @GetMapping("status")
    public AjaxResult getOrderInfoStatusList() {
        return AjaxResult.success(OrderStatusEnums.getStatusList());
    }


    //获取订单
    @ApiOperation("根据获取订单")
    @GetMapping("get/{id}")
    public AjaxResult getOrderInfo(@PathVariable("id") Long id) {
        Map<String,Object> map = orderInfoService.getOrderInfoMap(id);
        return AjaxResult.success(map);
    }


    //获取订单统计数量
    @ApiOperation("获取订单统计数据")
    @PostMapping("get/count")
    public AjaxResult getOrderInfoCountMap(@RequestBody OrderCountQueryVo orderCountQueryVo) {
        Map<String, Object> orderInfoCountMap = orderInfoService.getOrderInfoCountMap(orderCountQueryVo);
        return AjaxResult.success(orderInfoCountMap);
    }

}
